 <template>
  <div class="index-box" ref="index">
    <el-row :gutter="10">
      <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
        <div class="moneyTotal" ref="topData">
            <div class="item">
              <div class="money">{{topData.goodsTotalQuantity}}件</div>
              <div class="text">商品总计</div>
            </div>
            <div class="item">
              <div class="money">¥{{topData.totalOrderAmount}}</div>
              <div class="text">订单总计金额(元)</div>
            </div>
            <div class="item">
              <div class="money">¥{{topData.tradeCommissionTotal}}</div>
              <div class="text">交易提成总计(元)</div>
            </div>
            <div class="item">
              <div class="money">¥{{topData.platformReceivedTotalAmount}}</div>
              <div class="text">平台实收总计(元)</div>
            </div>
            <div class="item">
              <div class="money">¥{{topData.branchServiceChargeTotal}}</div>
              <div class="text">分账服务费总计(元)</div>
            </div>
            <div class="item">
              <div class="money">¥{{topData.ycReceivedTotalAmount}}</div>
              <div class="text">云仓实收总计(元)</div>
            </div>
        </div>
        <div class="search" ref="search">
          <el-form :inline="true" :model="searchForm" size="small" ref="searchForm" @submit.native.prevent
            class="demo-form-inline" id="searchBox">
            <el-form-item prop="orderNo" style="width: 280px;">
                <el-input v-model="searchForm.orderNo" clearable placeholder="订单编号" style="width: 280px!important;"></el-input>
            </el-form-item>
            <el-form-item prop="time">
              <el-date-picker v-model="time" type="daterange" align="right" unlink-panels range-separator="至"
                start-placeholder="下单开始日期" end-placeholder="下单结束日期" format="yyyy-MM-dd" value-format="yyyy-MM-dd"
                :picker-options="pickerOptions">
              </el-date-picker>
            </el-form-item>
            <el-form-item class="clearfix">
              <el-button type="primary" @click="handleSearch()" icon="el-icon-search">搜索</el-button>
              <el-button icon="el-icon-refresh" size="small" @click="resetSearch">重置</el-button>
              <el-button
                type="warning"
                icon="el-icon-download"
                size="small"
                :loading="btnLoading"
                @click="handleExport"
                v-has="'statistics:ebaoCloudMarket:down'"
              >导出</el-button>
            </el-form-item>
            <div class="actionBtnRight" style="margin-left:auto">
                <MyRefresh></MyRefresh>
                <MyTableColumnSet :tableColumn.sync="tableColumn" :hideTableColumn.sync="hideTableColumn" :tableColumnType.sync="tableColumnType"></MyTableColumnSet>
            </div>
          </el-form>
        </div>
        <div class="table" ref="table">
          <el-table :data="dataList" style="width: 100%"  border :height="tableHeight" stripe v-loading='loading'>
            <el-table-column prop="name" label="商品图" v-if="!hideTableColumn.includes('img')" align="center" width="110">
              <template #default="scope">
                 <el-image :src="scope.row.goodsLogo" class="img" fit="fill" v-image-preview="scope.row.goodsLogo"></el-image>
              </template>
            </el-table-column>
            <el-table-column prop="orderNo" label="订单编号" v-if="!hideTableColumn.includes('code')" align="center"></el-table-column>
            <el-table-column prop="goodsName" label="商品名称" v-if="!hideTableColumn.includes('storeName')" align="center" width="300"></el-table-column>
            <el-table-column prop="date" label="日期" v-if="!hideTableColumn.includes('time')" align="center" width="160"></el-table-column>
            <el-table-column prop="goodsNum" label="商品数量(件)" v-if="!hideTableColumn.includes('orderMoney')" align="center" width="100"></el-table-column>
            <el-table-column prop="totalOrderAmount" label="订单合计金额(元)" v-if="!hideTableColumn.includes('fuTotalMoney')" align="center"></el-table-column>
            <el-table-column prop="actualTotalAmount" label="实付合计金额(元)" v-if="!hideTableColumn.includes('shouTotalMoney')" align="center"></el-table-column>
            <el-table-column prop="tradeCommission" label="交易提成(元)" v-if="!hideTableColumn.includes('upMoney')" align="center"></el-table-column>
            <el-table-column prop="branchServiceCharge" label="分账服务费(元)" v-if="!hideTableColumn.includes('branchServiceCharge')" align="center"></el-table-column>
            <el-table-column prop="platformReceivedAmount" label="平台实收金额(元)" v-if="!hideTableColumn.includes('upMoneyCost')" align="center"></el-table-column>
            <el-table-column prop="ycReceivedAmount" label="云仓实收金额(元)" v-if="!hideTableColumn.includes('upMoneyTotal')" align="center"></el-table-column>
          </el-table>
        </div>
        <div class="page" ref="page">
          <MyPagination
            :total="total"
            :page.sync="searchForm.pageNum"
            :limit.sync="searchForm.pageSize"
            @pagination="dataInfo"
          />
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
  import common from '@/api/api';
  import {
    getYCYeePaySalesReportQuantity,
    ycYeePaySalesReportExport,
    ycYeePaySalesReportList
  } from '@/api/getData'
  import option from '../../common/option.js';

  export default {
    data() {
      return {
        loading: false,
        btnLoading:false,
        time:[],
        searchForm: {
          orderNo:'',
          pageNum:1,
          pageSize:20,
        },
        tableColumn:[{/*自定义表格列*/
            name:'序号',
            value:'number'
        },{
            name:'商品图',
            value:'img'
        },{
            name:'订单编号',
            value:'code'
        },{
            name:'商品名称',
            value:'storeName'
        },{
            name:'日期',
            value:'time'
        },{
            name:'商品数量(元)',
            value:'orderMoney'
        },{
            name:'订单合计金额(元)',
            value:'fuTotalMoney'
        },{
            name:'实付合计金额(元)',
            value:'shouTotalMoney'
        },{
            name:'交易提成(元)',
            value:'upMoney'
        },{
            name:'分账服务费(元)',
            value:'branchServiceCharge'
        },{
            name:'平台实收金额(元)',
            value:'upMoneyCost'
        },{
            name:'云仓实收金额(元)',
            value:'upMoneyTotal'
        }],

        hideTableColumn:[],/*自定义表格列需要隐藏的*/
        tableColumnType:'staffManagement',/*自定义表格列类型传参*/
        tableHeight:0,//table 高度
        topData:{},
        dataList:[],
        total: 0,
      }
    },
    computed:{
      pickerOptions: () => {
        return option.pickerOptions;
      }
    },
    mounted() {
      this.topDataInfo();
      this.dataInfo();
      this.$nextTick(() => {
          this.tableHeight = this.$refs.index.offsetHeight - this.$refs.topData.offsetHeight - this.$refs.search.offsetHeight  - this.$refs.page.offsetHeight - 55;
      })
    },
    methods: {
      topDataInfo(){
         let data = this.addDateRange(this.searchForm, this.time, 'startTime', 'endTime');
         getYCYeePaySalesReportQuantity(data).then((res)=>{
           this.topData = res.data;
         })
       },
       /** 导出按钮操作 */
       handleExport() {
         let data = this.addDateRange(this.searchForm, this.time, 'startTime', 'endTime');
         this.$modal.confirm('是否确认导出搜索数据项？').then(() => {
           this.btnLoading = true;
           return ycYeePaySalesReportExport(data);
         }).then(response => {
           this.$download.name(response.msg);
           this.btnLoading = false;
         }).catch(() => {});
      },
      handleSearch(){
          this.searchForm.pageNum = 1;
          this.dataInfo();
          this.topDataInfo();
      },
      async dataInfo() {
        try {
          let data = this.addDateRange(this.searchForm, this.time, 'startTime', 'endTime');
          this.loading = true;
          const result = await ycYeePaySalesReportList(data);
          if (result.code == 200) {
            this.total = result.total;
            this.dataList = result.rows;
          } else {
            this.$message.error(result.msg);
          }
          this.loading = false;
        } catch (err) {
          this.loading = false;
          console.log(err)
        }
      },
      resetSearch(){
        this.time = [];
        this.resetForm('searchForm');
        this.dataInfo();
         this.topDataInfo();
      },
    }
  }
</script>

<style scoped lang="scss">

  .el-table .el-dropdown-link{
      cursor: pointer;
      color: #61997A;
      margin-left: 5px;
  }
    .leftDialog{
      height:540px;
      overflow-y: auto;
    }
    .activeVerticalBox .activeItem{
      color:#61997A;
      cursor: pointer;
      margin: 0px;
      text-align: center;
      height:20px;
      line-height: 20px;
    }
    .activeVerticalBox .el-dropdown{
      display: flex;
      justify-content: center;
      color:#61997A;
      cursor: pointer;
    }
    .activeCheckedBox{
      border-top: 1px solid #ddd;
      padding:10px;
      height:52px;
      .el-tag{
        margin-right:10px;
      }
    }
    .rateBox /deep/ .el-rate__icon{
      margin-right: 0px;
    }
    .rateBox>p{
      margin: 0px;
    }
    .rateBox>p> /deep/ .el-rate{
      height:25px;
      line-height:25px;
      display:flex;
    }
    .rateBox>p> /deep/ .el-rate .el-rate__item{
      display:flex;
      align-items: center;
    }
    .rateBox .rateText{
      width:60px;
    }
    .rateBox .content{
      display: flex;
    }
    .rateBox .el-tooltip{
      width: 100px;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      display: inline-block;
    }
</style>
